<%@ page import="com.dbpms.until.Constants" %><%--
  Created by IntelliJ IDEA.
  User: 20275
  Date: 2023/11/18
  Time: 16:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@include file="/pages/common/head.jsp"%>

<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">修改学生信息</h1>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    学生管理 >> 修改学生信息
                </div>
                <div class="panel-body">
                    <form role="form" action="${pageContext.request.contextPath }/studentManage/update" method="post">
                        <input type="hidden" name="studentId" value="${studentInfo.studentId}">
                        <input type="hidden" name="oleChamberId" value="${studentInfo.studentChamberId}">
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <label>学号</label>
                                    <input class="form-control" name="studentNumber" value="${studentInfo.studentNumber}" required>
                                </div>
                                <div class="form-group">
                                    <label>姓名</label>
                                    <input class="form-control" name="studentName" value="${studentInfo.studentName}" required>
                                </div>
                                <div class="form-group">
                                    <label>性别</label>
                                    <select class="form-control" name="studentGender" required>
                                        <c:if test="${studentInfo.studentGender == 1}">
                                            <option value="1" selected> 男</option>
                                            <option value="0">女</option>
                                        </c:if>
                                        <c:if test="${studentInfo.studentGender == 0}">
                                            <option value="1"> 男</option>
                                            <option value="0" selected>女</option>
                                        </c:if>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>名族</label>
                                    <input class="form-control" name="studentFamilial" value="${studentInfo.studentFamilial}" required>
                                </div>
                                <div class="form-group">
                                    <label>身份证</label>
                                    <input class="form-control" name="studentIdCard" value="${studentInfo.studentIdCard}" required>
                                </div>
                                <div class="form-group">
                                    <label>年龄</label>
                                    <input class="form-control" name="studentAge" value="${studentInfo.studentAge}" required>
                                </div>

                            </div>
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <label>所属学院</label>
                                    <select class="form-control" id="college_select" name="studentCollegeId" required>
                                        <c:forEach items="${collegeInfos}" var="info">
                                            <c:if test="${studentInfo.studentCollegeId == info.collegeId}">
                                                <option value="${info.collegeId}" selected>${info.collegeName}</option>
                                            </c:if>
                                            <c:if test="${studentInfo.studentCollegeId != info.collegeId}">
                                                <option value="${info.collegeId}">${info.collegeName}</option>
                                            </c:if>
                                        </c:forEach>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>专业</label>
                                    <select class="form-control" id="speciality_select" name="studentSpecialityId" required>
                                        <option value="${studentInfo.studentSpecialityId}">${studentInfo.specialityName}</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>所属专业班级</label>
                                    <select class="form-control" id="class_select" name="studentClassId" required>
                                        <option value="${studentInfo.studentClassId}">${studentInfo.className}</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>所住宿舍</label>
                                    <select class="form-control" name="studentChamberId" required>
                                        <c:forEach items="${chamberInfos}" var="info">
                                            <c:if test="${studentInfo.studentChamberId == info.chamberId}">
                                                <option value="${info.chamberId}" selected>${info.chamberHotelNumber}</option>
                                            </c:if>
                                            <c:if test="${studentInfo.studentChamberId != info.chamberId}">
                                                <option value="${info.chamberId}">${info.chamberHotelNumber}</option>
                                            </c:if>
                                        </c:forEach>
                                    </select>
                                </div>

                                <input type="submit" class="btn btn-primary" value="修改">
                                <input type="reset" class="btn btn-warning" value="重置">
                            </div>
                        </div>

                    </form>

                </div>
            </div>
        </div>
    </div>
</div>
<c:if test="${message != null}">
    <script>
        alert("${message}")
    </script>
    <% session.removeAttribute(Constants.MESSAGE); %>
</c:if>
<script>
    $('#college_select').change(function() {
        var selectElement = document.getElementById('speciality_select');
        var value = $(this).val();
        console.log("学院id："+value)
        $.ajax({
            type: 'get',
            url: '${pageContext.request.contextPath }/studentManage/ByCollageIdSpec',
            data: { college_id: value},
            success: function(response) {
                selectElement.innerHTML = '';

                var newOption = document.createElement('option');
                newOption.text = "----请选择专业！----";
                newOption.value = 0;
                selectElement.add(newOption);

                for (let i = 0; i < response.data.length; i++) {
                    newOption = document.createElement('option');
                    newOption.text = response.data[i].specialityName;
                    newOption.value = response.data[i].specialityId;
                    selectElement.add(newOption);
                }
                console.log(response.data)
            },
            error: function(log) {
                // 在请求出错时的处理
                console.log('请求出错:'+log);
            }
        });
    });

    $('#speciality_select').change(function() {
        var selectElement = document.getElementById('class_select');
        var value = $(this).val();
        console.log("专业id："+value)
        $.ajax({
            type: 'get',
            url: '${pageContext.request.contextPath }/studentManage/BySpecIdClass',
            data: { speciality_id: value},
            success: function(response) {
                // 清空原内容
                selectElement.innerHTML = '';

                var newOption = document.createElement('option');
                newOption.text = "----请选择班级！----";
                newOption.value = 0;
                selectElement.add(newOption);

                for (let i = 0; i < response.data.length; i++) {
                    newOption = document.createElement('option');
                    newOption.text = response.data[i].className;
                    newOption.value = response.data[i].classId;
                    selectElement.add(newOption);
                }
            },
            error: function(log) {
                // 在请求出错时的处理
                console.log('请求出错:'+log);
            }
        });
    });
</script>

<%@include file="/pages/common/foot.jsp" %>
